//
//  ViewController.m
//  YMUIbutton
//
//  Created by 刘家俊 on 2017/7/27.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "ViewController.h"
#import "UIView+MHExtension.h"
#import "YMChangeButton.h"

@interface ViewController ()

/** 当前选中的标题按钮 */
@property (nonatomic, weak) YMChangeButton *selectedTitleButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGFloat buttonW = 200;
    CGFloat buttonH = 60;
    for (int i = 0; i < 5; i++) {
        YMChangeButton *button = [[YMChangeButton alloc] init];
        button.mh_x = 100;
        button.mh_y = i * (buttonH + 50) + 100;
        button.mh_width = buttonW;
        button.mh_height = buttonH;
        
        button.backgroundColor = [UIColor greenColor];
        [button setTitle:@"测试" forState:UIControlStateNormal];
        
        button.tag = i;
        
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:button];
    }
    
    NSLog(@"%@",self.view.subviews);
    YMChangeButton *firstTileButton = self.view.subviews.lastObject;
    firstTileButton.selected = YES;
    self.selectedTitleButton = firstTileButton;
}

- (void)buttonClick:(YMChangeButton *)sender
{
    
    self.selectedTitleButton.selected = NO;
    sender.selected = YES;
    self.selectedTitleButton = sender;
    
    
    NSLog(@"111");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
